home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / netdrv10.zip / NETDRIVE.DOC < prev    next >
Text File  |  1992-10-06  |  7KB  |  190 lines

  1. NETDRIVE v1.0
  2.  
  3. This program is my first using Turbo Pascal. I had a lot of fun doing it, and
  4. it will actually be useful to me. I hope it will be useful to others.
  5.  
  6. Usage info may be obtained by typing NETDRIVE ?.
  7.  
  8. Thanks to the folks at TurboPower Software for their environment routines.
  9. (especially Kim K. for help with adding the ParentEnv procedure)
  10. FInally, thanks to Stephen Cantrill for encouragement and for pointing me to
  11. TurboPower. (there were those who tried to discourage)
  12.  
  13. I have tested with MS & IBM DOS versions 3.30 and higher. These versions are
  14. all I have available on my net.
  15.  
  16. If you find a problem, I'll try to fix it. Hope you find it helpful.
  17.  
  18. Danny Dillon
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. ) 76004,2611
  26. To: Danny Dillon 70214,2221
  27.  
  28. Danny - TPENV doesn't have a routine to find the parent environment, although
  29. our commercial version in Object Professional does. The key to finding the
  30. parent is to note that MemW[PrefixSeg:$16] returns the prefix segment of any
  31. program's parent, which is usually the copy of COMMAND.COM that started it.
  32. Then, if we call the previous result ParentSeg, its environment is located at
  33. MemW[ParentSeg:$2C].
  34.  
  35. This is complicated by the fact that under some versions of DOS, the root copy
  36. of COMMAND.COM doesn't store its own environment segment at offset $2C. So you
  37. should compare ParentSeg to the segment of the root COMMAND.COM before
  38. proceeding.
  39.  
  40. In general, you can use the word at offset $16 to trace backwards in memory
  41. through as many parents as you have.
  42.  
  43. Hope this gets you going.
  44.  
  45. POSTED IN PCVENB
  46. -Kim, After your help with TPENV & the Parent environment, I patched together
  47. a procedure from parts of MasterEnv & CurrentEnv. It seems to work great with
  48. DOS 5, but I'm not confident with MY use of the OLD DOS logic for this ? ????
  49. procedure ParentEnv(var Env : EnvRec);........................................
  50. var...........................................................................
  51. ...ESeg : Word;...............................................................
  52. ...Mcb : Word;................................................................
  53. ...PSeg : Word;...............................................................
  54. ...Owner : Word;..............................................................
  55. begin.........................................................................
  56. ...with Env do begin..........................................................
  57. ...ClearEnvRec(Env);..........................................................
  58. ...Owner := MemW[0:(2+4*$2E)];................................................
  59. ...PSeg := MemW[PrefixSeg:$16];...............................................
  60. ...ESeg := MemW[PSeg:$2C];....................................................
  61. ...if Eseg = 0 then begin...........{ OLD DOS Master Environment Logic }......
  62. ......Mcb := Owner+MemW[Mcb:3];...............................................
  63. ...if (Mem[Mcb:0] <> Byte('M')) or (MemW[Mcb:1] <> Owner) then................
  64. ......Exit;...................................................................
  65. ......Eseg := Mcb+1;..........................................................
  66. ...end else...................................................................
  67. ......Mcb := Eseg-1;..........................................................
  68. ...EnvSeg := ESeg;............................................................
  69. ...EnvLen := MemW[Mcb:3] shl 4;...............................................
  70. end;..........................................................................
  71. end;...............{Please forgive the dots, I wanted the formatting to hold!}
  72. IF it is OK, everyone is welcome, and I am tickled. Please let me know either
  73. way, and THANK you VERY much !
  74.  
  75. PROGRAM NetDrive;
  76.  
  77. USES
  78.     Dos, Crt, TPEnv2;
  79.  
  80. {
  81. TPEnv2 was made from TPENV.ARC downloaded from the PCVENB Lib 6 (Turbo Power).
  82. I created a ParentEnv() procedure from parts of provided procedures.
  83. Thank you Turbo Power !
  84. }
  85.  
  86. VAR
  87.     DirExists : SearchRec;
  88.     DriveList : String[21];
  89.     ChkDrive  : String[1];
  90.     CHkFile   : String[18];
  91.     NovDrive  : String[2];
  92.     Counter   : Integer;
  93.     Percent1  : String[20];
  94.     Quiet     : Boolean;
  95.  
  96. PROCEDURE Syntax;
  97. Begin
  98. WriteLn('NETDRIVE v1.0');
  99. WriteLn('');
  100. WriteLn('A NetWare utility by Danny Dillon  (70214,2221)');
  101. WriteLn('');
  102. WriteLn('NETDRIVE sets the environmental variable "NETDRIVE" to the first drive where');
  103. WriteLn('LOGIN.EXE is found, ( starting with F: and searching through Z: ). It is meant');
  104. WriteLn('to be used in a batch file immediately following NETx, allowing the supervisor');
  105. WriteLn('to write the same batch file for for all workstations, without having to allow');
  106. WriteLn('for a different lastdrive. ');
  107. WriteLn('');
  108. WriteLn('     ...');
  109. WriteLn('     NETX');
  110. WriteLn('     NETDRIVE <Q>');
  111. WriteLn('     If ErrorLevel 0 %NETDRIVE%\LOGIN\LOGIN');
  112. WriteLn('');
  113. WriteLn('Optional Parameter Q turns off console error messages.');
  114. WriteLn('Any other other parameter displays this screen.');
  115. WriteLn('Errorlevel 0 indicates \LOGIN\LOGIN.EXE was found & NETDRIVE set.');
  116. WriteLn('Errorlevel 1 indicates \LOGIN\LOGIN.EXE was not found.');
  117. WriteLn('ErrorLevel 2 indicated a problem writing to the environment.');
  118. WriteLn('');
  119. WriteLn('This program has been tested with MS & IBM DOS 3.3 & up !');
  120. WriteLn(' ');
  121. end;
  122.  
  123. Begin {MAIN PROGRAM}
  124.     Quiet := False;
  125.     DriveList := 'FGHIJKLMNOPQRSTUVWXYZ';
  126.     If ParamCount <> 0 then begin
  127.         Percent1 := ParamStr(1);
  128.         Percent1[1] := Upcase(Percent1[1]);
  129.         If Percent1 <> 'Q' then Syntax;
  130.         Quiet := True;
  131.     end;
  132.  
  133.     NovDrive := '';
  134.     For Counter := 1 to 21 do
  135.         Begin
  136.             ChkDrive := DriveList[Counter];
  137.             CHkFile := Concat(ChkDrive,':\LOGIN\LOGIN.EXE');
  138.             FindFirst(ChkFile, AnyFile, DirExists);
  139.             If (DosError = 0) then Begin
  140.                 NovDrive := Concat(ChkDrive,':');
  141.                 Counter := 21;
  142.             end;
  143.         end;
  144.     If Length(NovDrive) < 2 then Begin
  145.         If NOT Quiet then WriteLn('NETDRIVE ERROR: \LOGIN\LOGIN.EXE not found !');
  146.         Halt(1);
  147.     end;
  148.     ParentEnv(E);
  149.     if not SetEnvStr(E, 'NETDRIVE', NovDrive) then Begin
  150.         If NOT Quiet then WriteLn('Not enough space in environment to add NETDRIVE.');
  151.         Halt(2);
  152.     end;
  153.  
  154. { The following is the code for the ParentEnv procedure I added to TPENV.
  155.   It was derived from parts of CurrentEnv & MasterEnv.
  156.  
  157.   procedure ParentEnv(var Env : EnvRec);
  158.   var
  159.     ESeg : Word;
  160.     Mcb : Word;
  161.      PSeg : Word;
  162.      Owner : Word;
  163.   begin
  164.     with Env do begin
  165.       ClearEnvRec(Env);
  166.         Owner := MemW[0:(2+4*$2E)];
  167.         PSeg := MemW[PrefixSeg:$16];
  168.         ESeg := MemW[PSeg:$2C];
  169.         if Eseg = 0 then begin
  170.           Mcb := Owner+MemW[Mcb:3];
  171.           if (Mem[Mcb:0] <> Byte('M')) or (MemW[Mcb:1] <> Owner) then
  172.              Exit;
  173.           Eseg := Mcb+1;
  174.         end else
  175.           Mcb := Eseg-1;
  176.         EnvSeg := ESeg;
  177.         EnvLen := MemW[Mcb:3] shl 4;
  178.      end;
  179.   end;
  180.  
  181. }
  182. End.
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.